<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>会员登录</title>
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" />
<script src="js/jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<!-- 引入自定义css文件 style.css -->
<link rel="stylesheet" href="css/style.css" type="text/css" />

<style>
body {
	margin-top: 20px;
	margin: 0 auto;
}

.carousel-inner .item img {
	width: 100%;
	height: 300px;
}
</style>
<script type="text/javascript">
	function addCart() {
		//获得购买的商品的数量
		var buyNum=$("#buyNum").val();
		location.href="${pageContext.request.contextPath }/product?method=addProductToCart&pid=${product.pid}&buyNum="+buyNum;
	}
</script>
</head>

<body>
	<!-- 引入header.jsp -->
	
		<div id="header"></div>
		<span id="currentUser">2</span>
	<div class="container">
		<div class="row">
			<div
				style="border: 1px solid #e4e4e4; width: 930px; margin-bottom: 10px; margin: 0 auto; padding: 10px; margin-bottom: 10px;">
				<a href="./index.htm">首页&nbsp;&nbsp;&gt;</a> <a href="./蔬菜分类.htm">蔬菜&nbsp;&nbsp;&gt;</a>
				<a>无公害蔬菜</a>
			</div>

			<div style="margin: 0 auto; width: 950px;">
				<div class="col-md-6">
					<img  id="tp" style="opacity: 1; width: 400px; height: 350px;" title=""
						class="medium"
						src="">
				</div>

				<div class="col-md-6">
					<div>
						<strong id="gname"></strong>
					</div>
					<div
						style="border-bottom: 1px dotted #dddddd; width: 350px; margin: 10px 0 10px 0;">
						<div>编号：<span id="gid"></span></div>
					</div>

					<div style="margin: 10px 0 10px 0;">
						亿家价: <strong style="color: #ef0101;" id="jg"></strong> 参 考 价：
						<del>￥${goods.gprice}元/份</del>
					</div>

					<div style="margin: 10px 0 10px 0;">
						促销: <a target="_blank" title="限时抢购 (2014-07-30 ~ 2015-01-01)"
							style="background-color: #f07373;">限时抢购</a>
					</div>

					<div
						style="padding: 10px; border: 1px solid #e7dbb1; width: 330px; margin: 15px 0 10px 0;; background-color: #fffee6;">
						<div style="margin: 5px 0 10px 0;">白色</div>

						<div
							style="border-bottom: 1px solid #faeac7; margin-top: 20px; padding-left: 10px;">
							购买数量: <input id="buyNum" name="number" value="1"
								maxlength="4" size="10" type="text">
						</div>

						<div style="margin: 20px 0 10px 0;; text-align: center;">
							<a href="javascript:void(0);"> <input
								style="background: url('./images/product.gif') no-repeat scroll 0 -600px rgba(0, 0, 0, 0); height: 36px; width: 127px;"
								name="jrgwc" id="jrgwc" value="加入购物车" type="button">
							</a> &nbsp;收藏商品
						</div>
					</div>
					<div>
						<a href="/product?method=productList&cid=1&currentPage=2">返回列表页面</a>
					</div>
				</div>
			</div>
			<div class="clear"></div>
			<div style="width: 950px; margin: 0 auto;">
				<div
					style="background-color: #d3d3d3; width: 930px; padding: 10px 10px; margin: 10px 0 10px 0;">
					<strong>商品介绍</strong>
				</div>

				<div>
										<div id="gsummary"></div>
				</div>

				<div style="background-color:#d3d3d3; width:930px; padding: 10px 10px; margin: 10px 0 10px 0;">
					<strong>商品参数</strong>
				</div>
				<div style="margin-top: 10px; width: 900px;">
					<table class="table table-bordered">
						<tbody>
							<tr class="active">
								<th colspan="2">基本参数</th>
							</tr>
							<tr>
								<th width="10%">级别</th>
								<td width="30%">标准</td>
							</tr>
							<tr>
								<th width="10%">标重</th>
								<td>500</td>
							</tr>
							<tr>
								<th width="10%">浮动</th>
								<td>200</td>
							</tr>
						</tbody>
					</table>
				</div>

				<div style="background-color: #d3d3d3; width: 900px;">
					<table class="table table-bordered">
						<tbody>
							<tr class="active">
								<th><strong>商品评论</strong></th>
							</tr>
							<tr class="warning">
								<th>暂无商品评论信息 <a>[发表商品评论]</a></th>
							</tr>
						</tbody>
					</table>
				</div>

				<div style="background-color: #d3d3d3; width: 900px;">
					<table class="table table-bordered">
						<tbody>
							<tr class="active">
								<th><strong>商品咨询</strong></th>
							</tr>
							<tr class="warning">
								<th>暂无商品咨询信息 <a>[发表商品咨询]</a></th>
							</tr>
						</tbody>
					</table>
				</div>
			</div>

		</div>
	</div>
		<div id="footer"></div>
	
		<script src="https://www.layuicdn.com/layui/layui.all.js"></script>

	<!-- 引入footer.jsp -->
	<script type="text/javascript">
//加载头部
$.post('header.jsp',{},function(data){
	$("#header").html(data);
},'text');


//加载尾部
$.post('footer.jsp',{},function(data){
	$("#footer").html(data);
},'text');


</script>

</body>

</html>
<script>
//js的方式拿到地址栏参数
function getUrlSearch(name) {
	  // 未传参，返回空
	  if (!name) return null;
	  // 查询参数：先通过search取值，如果取不到就通过hash来取
	  var after = window.location.search;
	  after = after.substr(1) || window.location.hash.split('?')[1];
	  // 地址栏URL没有查询参数，返回空
	  if (!after) return null;
	  // 如果查询参数中没有"name"，返回空
	  if (after.indexOf(name) === -1) return null;
	 
	  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
	  // 当地址栏参数存在中文时，需要解码，不然会乱码
	  var r = decodeURI(after).match(reg);
	  // 如果url中"name"没有值，返回空
	  if (!r) return null;
	  return r[2];
	}
</script>
<script>
	layui.use(['form','jquery','laypage'],function(){
		//取得地址栏的gid
		var $=layui.jquery;
		var gid=getUrlSearch('gid');
		var obj={"gid":gid};
		//发送ajax请求查询
		$.post('/heima/findGoodsByCriteria',obj,function(date){
			console.log(date);
			var gname=date[0].gname;
			var gprice=date[0].gprice;
			var gsummary=date[0].gsummary;
			var tp=date[0].gphoto;
			var gid=date[0].gid;			
			$("#gname").text(gname);
			$("#jg").text(gprice);
			$("#gsummary").text(gsummary);
			$("#tp").attr("src",tp);
			$("#gid").text(gid);
		},'json');
		insertCart(gid);
	});
	
	function insertCart(gid){
		$("input[name=jrgwc]").click(function(){
			var user=$("#currentUser").text();
			var number=$("input[name=number]").val();
			number=parseInt(number);
			var uid=user;
			var gid=20;
			var gname=$("#gname").text();
			var gphoto=$("#tp").attr("src");
			var gprice=$("#jg").text();
			gprice =parseInt(gprice)*number;
			var count=number;
			var obj={
					"uid":uid,
					"gid":gid,
					"gphoto":gphoto,
					"gname":gname,
					"gprice":gprice,
					"count":count
			};
			$.post('/heima/inserMyCart',obj,function(data){
				if(data.msg=='success'){
					layer.alert('加入购物车成功');
				}else if(date.msg=='fail'){
					layer.alert('加入购物车失败');
				}
			},'json');
		});
	}
</script>